<?php
include 'public.php';
$id = $_GET['id'];
 
$sql = "select o.id,o.user_name,o.addtime,o.status,r.name,r.phone,r.address from ".PRE."order o,".PRE."order_receiver r where  o.rec_id = r.id and o.id='{$id}' order by o.id";
$result = mysql_query($sql);
$orderlist = mysql_fetch_assoc($result);
//查询订单中所有商品
$sql = "select  g.id,name,image,og.price,num from ".PRE."order_goods og,".PRE."goods g  where og.goods_id = g.id and order_id='{$id}'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){$goodslist[] = $row;}

if(empty($goodslist)) {echo '<meta http-equiv="Refresh" content="0; url=order.php"/>';exit;}

?>
<div class="admin_main_nav">订单管理&gt;&gt;订单详情</div>
<div class="shopcar">
	<div class="mt20">
		<table cellspacing="0" cellpadding="0" width="800">
			<tr class="color">
				<th>订单号</th>
				<th>下单时间</th>
				<th width="120">订单状态</th>
				<th width="80">操作</th>
			</tr>
			<tr>
				<td><?php echo $orderlist['id'] ?></td>
				<td><?php echo date('Y-m-d H:i:s',$orderlist['addtime']) ?></td>
				<td><?php 
						switch($orderlist['status']){
							case 0:
								echo '<font color="red">等待发货</font>';
								break;
							case 1:
								?>
								<div class="action">
								<div class="fl"><a class="ack" href="action.php?a=ack&id=<?php echo $orderlist['id']?>"><div class="icon fl ack_i"></div><div class="fl">确认收货</div></a></div>
								</div>
								
								<?php
								break;
							case 2:
								echo '<font color="green">交易完成</font>';
								break;
						} 
				?></td>
				<td>
					<div class="action">
						<?php if ($orderlist['status'] == 0):?>
						<div class="fl"><a class="del" href="action.php?a=rm&id=<?php echo $orderlist['id']?>"><div class="icon fl del_i"></div><div class="fl">取消</div></a></div>
						<?php else:?>
						<div class="fl"><a class="nodel"><div class="icon fl del_i"></div><div class="fl">取消</div></a></div>
						<?php endif;?>
					</div>
				</td>
			</tr>
			<tr>
				<th>收件人信息：</th>
				<td colspan="3" style="text-align:left;"><?php echo $orderlist['name'].'　'.$orderlist['phone'].'　'.$orderlist['address']?></td>
			</tr>
		</table>
	</div>
	
	
	<div class="mt20">
		<table cellspacing="0" cellpadding="0" width="800">
			<tr class="color">
				<th>商品</th>
				<th>商品名</th>
				<th>单价</th>
				<th>数量</th>
				<th>小计</th>
				<?php if($orderlist['status'] == 2):?>
				<th>操作</th>
				<?php endif;?>
			</tr>
			<?php foreach($goodslist as $val):?>
				<tr class="goods">
					<td><a href="../detail.php?gid=<?php echo $val['id']?>"><img src="<?php echo APP ?>/upload/<?php echo $val['image']?>"  height="80"/></a></td>
					<td><a href="../detail.php?gid=<?php echo $val['id']?>"><?php echo $val['name']?></a></td>
					<td><?php echo $val['price']?></td>
					<td><?php echo $val['num']?></td>
					<td><?php echo $val['price']*$val['num']?></td>
					<?php if($orderlist['status'] == 2):?>
						<?php 
							$sql = "select id from ".PRE."comment where user_name='{$_SESSION['home']['name']}' and goods_id='{$val['id']}' and order_id='{$id}'";
							$result = mysql_query($sql);
							if($result && mysql_affected_rows()>0):
						?>
							<td><font color="green">已评</fort></td>
						<?php else:?>
							<td><a href="comment.php?gid=<?php echo $val['id']?>&oid=<?php echo $id?>"><font color="red">评价</fort></a></td>
						<?php endif;?>
					<?php endif;?>
				</tr>
			<?php $total += $val['price']*$val['num'];  endforeach;?>
				<tr class="color">
					<td colspan="6" style="text-align:right;"><span>总计：￥<?php echo number_format($total,2,'.',',') ?> </span></td>
				</tr>
		</table>
	</div>
</div>


<?php include 'public_b.php';?>
